package com.yitiao.socket.chatroom.demo;

import com.yitiao.socket.chatroom.CommonConst;
import lombok.SneakyThrows;

import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousServerSocketChannel;

public class AioServer {
    private AsynchronousServerSocketChannel asyncServer;

    @SneakyThrows
    public void start(){
        asyncServer = AsynchronousServerSocketChannel.open();
        asyncServer.bind(new InetSocketAddress(CommonConst.PORT));
        while (true){
            asyncServer.accept(null,new AcceptHandler());
            System.out.println("server wait connect...");
            int read = System.in.read();
        }
    }

    public static void main(String[] args) {
        AioServer server = new AioServer();
        server.start();
    }
}
